<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/alert.min.js"></script>
    <script>
        function editCategory(goodId, categoryId, goodName, price, stock) {
            console.log(goodId)
            console.log(categoryId)
            console.log(goodName)
            console.log(price)
            console.log(stock)
            document.querySelector("input[name='updateGoodId']").value = goodId;
            document.querySelector("input[name='updateCategoryId']").value = categoryId;
            document.querySelector("input[name='updateGoodName']").value = goodName;
            document.querySelector("input[name='updateGoodPrice']").value = price;
            document.querySelector("input[name='updateGoodStock']").value = stock;
            document.getElementById("editForm").submit();
        }
        <%--$(function(){--%>
        <%--    $('.del').on('click', function () {--%>
        <%--        $.confirm('确认要删除吗？', function (isConfirm) {--%>
        <%--            if (isConfirm) {--%>
        <%--                window.location.href="${pageContext.request.contextPath}/goods?method=del&id="+id--%>
        <%--            }--%>
        <%--        });--%>
        <%--    });--%>

        <%--});--%>
        function del(id) {
            $.confirm('确认要删除吗？', function (isConfirm) {
                if (isConfirm) {
                    window.location.href="${pageContext.request.contextPath}/goods?method=del&id="+id
                }
            });
        }
    </script>
</head>
<body>

<div style="padding:0px; margin:0px;">
    <ul class="breadcrumb" style="  margin:0px; " >
        <li><a href="#">商品管理</a></li>
        <li>商品列表</li>
    </ul>
</div>
<div class="row alert alert-info" style="margin:5px 0px 5px 0px; padding:3px;">
    <form class="form-inline" method="post" accept-charset="UTF-8"
          action="${pageContext.request.contextPath}/goods?method=list">
        <div class="form-group">
            <input type="text" name="kw" class="form-control" id="activename" placeholder="请输入关键字">
        </div>
        <input type="submit" class="btn btn-danger" value="查询"/>
        <a class="btn btn-success" href="${pageContext.request.contextPath}/pages/goods/goods_add.jsp">增加</a>
    </form>
</div>
<div class="row" style="padding:15px; padding-top:0px;">
    <table class="table  table-condensed table-striped">
        <tr>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>商品库存</th>
            <th>商品类型</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${list}" var="item">
            <tr>
                <td>${item.goodsId}</td>
                <td>${item.goodsName}</td>
                <td>${item.goodsPrice}</td>
                <td>${item.goodsStock}</td>
                <td>${item.categoryName}</td>
                <td>
                    <a href="#">
                        <span class="glyphicon glyphicon-edit" aria-hidden="true"
                              onclick="editCategory('${item.goodsId}','${item.categoryId}','${item.goodsName}','${item.goodsPrice}','${item.goodsStock}')">修改</span>
                    </a>
                    <a href="#">
                        <span class="glyphicon glyphicon-trash del" onclick="del('${item.goodsId}')" aria-hidden="true">删除</span>
                    </a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <form id="editForm" action="${pageContext.request.contextPath}/pages/goods/goods_update.jsp" method="post">
        <input type="hidden" name="updateGoodId">
        <input type="hidden" name="updateCategoryId">
        <input type="hidden" name="updateGoodName">
        <input type="hidden" name="updateGoodPrice">
        <input type="hidden" name="updateGoodStock">
    </form>
</div>
</body>
</html>

